package com.tepth.busfix.view;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.tepth.busfix.R;
import com.tepth.busfix.bean.reponse.Trouble;
import com.tepth.busfix.bean.reponse.TroubleContent;
import com.tepth.busfix.main.partsearch.PartSearchActivity;

import java.util.List;

/**
 * Created by zhangyu on 2017/3/21.
 */

public class ChooseOperatorDialog extends Dialog {

    public ChooseOperatorDialog(@NonNull final Activity context,
                                final List<TroubleContent.Operation> list
            , final Trouble trouble, final Fragment fragment) {
        super(context);
        View view = LayoutInflater.from(context).
                inflate(R.layout.dialog_choose_actions, null);
        ListView listView = (ListView) view.findViewById(R.id.list_view);
        ArrayAdapter<TroubleContent.Operation> adapter = new ArrayAdapter<>(context, R.layout.item_text, list);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(context, PartSearchActivity.class);
                intent.putExtra(PartSearchActivity.EXTRA_NAME, list.get(position));
//                intent.putExtra(PartSearchActivity.CLASSFICATION, trouble.getClassification());
//                intent.putExtra(PartSearchActivity.TROUBLE_TYPE_ID, trouble.getTroubleTypeId());
//                intent.putExtra(PartSearchActivity.TROUBLE_NAME, trouble.getName());
                intent.putExtra(PartSearchActivity.TROUBLE, trouble);
                fragment.startActivityForResult(intent, PartSearchActivity.RESULT_CODE);
                dismiss();
            }
        });
        setContentView(view);
    }

}
